package com.uubx.controller;

import com.uubx.mapper.RoleMapper;
import com.uubx.pojo.Permission;
import com.uubx.pojo.Role;
import com.uubx.result.Result;
import com.uubx.result.ResultUtils;
import com.uubx.service.RoleService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @Author wuguojun
 * @Date 2020/12/27 22:08
 * @Version 1.0
 */
@Controller
@ResponseBody
@RequestMapping("/permission")
@Api(description ="权限相关的接口文档")
public class PermissionController {

    @Autowired
    private RoleService roleService;

    /**
     * 查询表中所有的权限
     * @return
     */
    @RequestMapping(value = "/queryAllPermission",method = RequestMethod.GET)
    @ApiOperation(value = "查询表中所有的权限",notes = "查询表中所有的权限",httpMethod = "GET",
            authorizations = {@Authorization(value = "token")})//请求需要token
    @ApiResponses({@ApiResponse(code = 200,message = "请求成功！data代表返回的数据"),
            @ApiResponse(code=500,message = "服务器开差了")})
    public Result queryAllPermission(){
        List<Permission> permissions = roleService.queryAllPermission();
        return ResultUtils.buildSuccess(permissions);
    }

    /**
     * 查询角色所拥有的权限
     * @return
     */
    @RequestMapping(value = "/queryRoleHavingPermission",method = RequestMethod.GET)
    @ApiOperation(value = "查询角色所拥有的权限",notes = "查询角色所拥有的权限",httpMethod = "GET",
            authorizations = {@Authorization(value = "token")})//请求需要token
    @ApiImplicitParams({@ApiImplicitParam(name = "name",value = "角色名字",required=true,paramType = "query")})
    @ApiResponses({@ApiResponse(code = 200,message = "请求成功！data代表返回的数据"),
            @ApiResponse(code=500,message = "服务器开差了")})
    public Result queryRoleHavingPermission(String name){
        List<Permission> permissions = roleService.queryPermissionByRoleName(name);
        return ResultUtils.buildSuccess(permissions);
    }

}
